// pages/submit/components/SelectBox.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    promotions: {
      type: Array,
    },
    couponCodeName:{
      type:String
    }
  },
  lifetimes: {
    attached() {
      var _this = this
      console.log(_this.data.promotions)
      _this.data.promotions.forEach(function(item) {
        if (item.type == 0) {
          item.typeName = '新人礼包'
        } else if (item.type == 1) {
          item.typeName = '消费后送'
        } else if (item.type == 2) {
          item.typeName = '扫码领券'
        } else if (item.type == 3) {
          item.typeName = '满减'
        } else if (item.type == 4) {
          item.typeName = '满折'
        } else if (item.type == 5) {
          item.typeName = '满赠'
        } else if (item.type == 6) {
          item.typeName = '满包邮'
        } else if (item.type == 7) {
          item.typeName = '买送'
        } else if (item.type == 8) {
          item.typeName = '秒杀'
        } else if (item.type == 9) {
          item.typeName = '第二件半价'
        } else if (item.type == 10) {
          item.typeName = '新人价'
        }
      })
      _this.setData({
        promotions: _this.data.promotions
      })
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    coupons: [{
        title: '省1:五一特惠神券',
        subtitle: '¥2.00',
        price: '2.00',
        status: false
      },
      {
        title: '省2:五一特惠神券',
        subtitle: '¥2.00',
        price: '2.00',
        status: false
      },
      {
        title: '省3:五一特惠神券',
        subtitle: '¥2.00',
        price: '2.00',
        status: false
      }
    ],
    index: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    chooseClick(data) {
      var _this = this
      console.log(data)
      _this.data.coupons.forEach(function(item) {
        item.status = false
      })
      _this.data.coupons[data.currentTarget.dataset.index].status = !_this.data.coupons[data.currentTarget.dataset.index].status
      _this.data.index = data.currentTarget.dataset.index
      _this.setData({
        coupons: _this.data.coupons,
        index: _this.data.index
      })
    },
    completeClick() {
      var completecoupons = {
        completecoupons: this.data.coupons[this.data.index]
      };
      this.triggerEvent("completecoupons", completecoupons)
    },
    cencleClick() {
      var cenclecoupons = {
        cenclecoupons: false
      };
      this.triggerEvent("cenclecoupons", cenclecoupons)
    }
  }
})